/**
 * Created by losor on 2017/3/8.
 */
public class _167_TwoSumIIInputArrayIsSorted {
    public static void main(String[] args) {

    }

    public int[] twoSum(int[] numbers, int target) {
        int[] index = new int[2];
        index[1] = numbers.length-1;

        while(numbers[index[0]] + numbers[index[1]] != target && index[0] != index[1]){
            while (numbers[index[0]] + numbers[index[1]]>target){
                --index[1];
            }
            while (numbers[index[0]] + numbers[index[1]]<target){
                ++index[0];
            }
        }
        index[0]++;
        index[1]++;
        return index;
    }

    //整理好变量对速度影响还是比较大的
    public int[] twoSumBigboss(int[] num, int target) {
        int[] indice = new int[2];
        if (num == null || num.length < 2) return indice;
        int left = 0, right = num.length - 1;
        while (left < right) {
            int v = num[left] + num[right];
            if (v == target) {
                indice[0] = left + 1;
                indice[1] = right + 1;
                break;
            } else if (v > target) {
                right --;
            } else {
                left ++;
            }
        }
        return indice;
    }
}
